package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysNotice;
import io.mybatis.example.springboot.service.SysNoticeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_notice - 通知公告表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysNotices")
public class SysNoticeController {

  @Autowired
  private SysNoticeService sysNoticeService;

  @PostMapping
  public DataResponse<SysNoticeDO> save(@RequestBody SysNoticeDO sysNotice) {
    return DataResponse.ok(sysNoticeService.save( sysNotice));
  }

  @GetMapping
  public RowsResponse<SysNoticeDO> findList(@RequestBody SysNoticeDO sysNotice) {
    return RowsResponse.ok(sysNoticeService.findList( sysNotice));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysNoticeDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysNoticeService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysNoticeDO> update(@PathVariable("id") Long id, @RequestBody SysNoticeDO sysNotice) {
    sysNotice.setId(id);
    return DataResponse.ok(sysNoticeService.update( sysNotice));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysNoticeService.deleteById(id) == 1);
  }

}
